import {
	getSystemConfig
} from '@/api/login.js'
import constant from '@/utils/constant'
import storage from '@/utils/storage'
export default {
	namespaced: true,
	state: {
		systemConfig: {
			captchaOpenFlag: false, // 是否展示验证码
			passwordStrategy: [] // 密码校验规则
		}
	},
	mutations: {
		SET_SYSTEM_CONFIG(state, config) {
			state.systemConfig = config
			storage.set(constant.systemConfig, config)
		}
	},
	actions: {
		getSystemConfig({
			commit
		}) {
			return new Promise((resolve, reject) => {
				getSystemConfig().then(res => {
					if (res.data.code == 200) {
						const result = res.data.result
						commit('SET_SYSTEM_CONFIG', result)
						resolve(res)
					} else {
						resolve(res)
					}
				}).catch(error => {
					reject(error)
				})
			})
		}
	}
}